/*
 * @Descripttion: 
 * @version: V1.0.0
 * @Author: LeonHe
 * @Date: 2021-05-29 17:30:13
 * @LastEditTime: 2021-05-30 16:07:32
 */
#ifndef __PARAM_MNG_H_
#define __PARAM_MNG_H_

#include "main.h"
#include "stmflash.h"

#define FLASH_ADDR_PARAM_LIST 0x0800F000

#define PARAM_VALID_FLAG 0xABCD

//16类*32个
typedef struct
{
    //1 状态管理 2000
    uint16_t paramValid;
    uint16_t basicCalibrated;
    uint16_t focMode;
    uint16_t statusRev[32-3];

    //2 编码器 2032
    uint16_t encZero;
    uint16_t EncRev[32-1];

    //3 电流传感器 2064
    uint16_t CurrentOffsetA;
    uint16_t CurrentOffsetB;
    uint16_t CurRev[32-2];

    //4 FOC电流环 2096
    uint16_t focIdPidKp;
    uint16_t focIdPidKi;
    uint16_t focIdPidKd;
    uint16_t focIqPidKp;
    uint16_t focIqPidKi;
    uint16_t focIqPidKd;
    uint16_t focCurrRev[32-6];

    //5 FOC速度环 2128
    uint16_t focSpdPidKp;
    uint16_t focSpdPidKi;
    uint16_t focSpdPidKd;
    uint16_t focSpdRev[32-3];

    //6 FOC位置环 2160
    uint16_t focPosPidKp;
    uint16_t focPosPidKi;
    uint16_t focPosPidKd;
    uint16_t focPosRev[32-3];

    //7 MODBUS参数 2192
    uint16_t modbusBaudrateH;
    uint16_t modbusBaudrateL;
    uint16_t modbusRev[32-2];

    //Rev
    uint16_t Reserved[(16-7)*32];
}ParamListStDef;


extern ParamListStDef *pParamListSt;

uint8_t paramMngInit(uint8_t resetFlg);

static inline void paramMngWrite(void)
{
    STMFLASH_Write(FLASH_ADDR_PARAM_LIST, (uint16_t*)pParamListSt, sizeof(ParamListStDef)/sizeof(uint16_t));
}

static inline void paramMngRead(void)
{
    STMFLASH_Read(FLASH_ADDR_PARAM_LIST, (uint16_t*)pParamListSt, sizeof(ParamListStDef)/sizeof(uint16_t));
}


#endif
